package com.metaera.app.ui.adapters;

import android.content.Context;
import android.graphics.Color;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.data.model.SearchResultResponse;
import com.metaera.app.ui.activities.ArticleDetailsActivity;
import com.metaera.app.ui.activities.ChoiceTopicDetailsActivity;
import com.metaera.app.utils.SpannableStringHelper;

import androidx.annotation.NonNull;

public class SearchResultChoiceTopicAdapter extends BaseQuickAdapter<SearchResultResponse, BaseViewHolder> {

    private final String keyword;

    public SearchResultChoiceTopicAdapter(String keyword) {
        super(R.layout.item_search_choice_topic);
        this.keyword = keyword;
        setOnItemClickListener((adapter, view, position) -> {
            Context context = view.getContext();
            SearchResultResponse item = getItem(position);
            context.startActivity(ArticleDetailsActivity.newInstance(context, item.getId()));
//            context.startActivity(ChoiceTopicDetailsActivity.newInstance(context, item.getId()));
        });
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, SearchResultResponse item) {
        holder.setText(R.id.tv_title, SpannableStringHelper.matchText(Color.parseColor("#3756FD"),item.getTitle(),keyword));
    }

}
